function y = ComputeSplineValue( S, x )
x = double(x);
N = size(S, 2);
if x <= S(1).xp
    s = S(1);
else
    if x >= S(N).xp
        s = S(N);
    else
        i = 1;
        j = N;
        while (i + 1 < j)
            p = i + idivide(int32(j - i), 2);
            if (x <= S(p).xp)
                j = p;
            else
                i = p;
            end;
        end;
        s = S(j - 1);
    end;
end;
dx = x - s.xp;
y = polyval([s.d, s.c, s.b, s.a], dx);
    
end

